#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT([libsbase], [1.0.6], [SounOS@gmail.com])
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE

# Checks for programs.
AC_PROG_CXX
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_LIBTOOL
AM_PROG_CC_C_O

# Checks for libraries.
#pthread
havepthread=no
AC_CHECK_LIB(pthread,pthread_create,havepthread=yes)
if test "$havepthread" = "yes" ; then
    CPPFLAGS="${CPPFLAGS} -DHAVE_PTHREAD"
    LDFLAGS="${LDFLAGS} -pthread"
    LIBS="${LIBS} -pthread"
fi
#ssl
havessl=no
AC_CHECK_LIB(ssl, SSL_read, havessl=yes)
if test "$havessl" = "yes" ; then
    CPPFLAGS="${CPPFLAGS} -DHAVE_SSL"
    LDFLAGS="${LDFLAGS} -lssl -lcrypto"
    LIBS="${LIBS} -lssl -lcrypto"
fi
#zlib
havezlib=no
AC_CHECK_LIB(z, compress, havezlib=yes)
if test "$havezlib" = "yes" ; then
    CPPFLAGS="${CPPFLAGS} -DHAVE_ZLIB"
    LDFLAGS="${LDFLAGS} -lz"
    LIBS="${LIBS} -lz"
fi
#bz2lib
havebz2lib=no
AC_CHECK_LIB(bz2, BZ2_bzCompress, havebz2lib=yes)
if test "$havebz2lib" = "yes" ; then
    CPPFLAGS="${CPPFLAGS} -DHAVE_BZ2LIB"
    LDFLAGS="${LDFLAGS} -lbz2"
    LIBS="${LIBS} -lbz2"
fi

# FIXME: Replace `main' with a function in `-levbase':
AC_CHECK_LIB([evbase], [evbase_init])

# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h fcntl.h locale.h netdb.h netinet/in.h stdint.h stdlib.h string.h strings.h sys/file.h sys/socket.h sys/time.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM

# Checks for library functions.
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_FORK
AC_FUNC_LSTAT
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
AC_FUNC_MKTIME
AC_FUNC_MMAP
AC_FUNC_REALLOC
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_FUNC_STAT
AC_CHECK_FUNCS([gethostbyname getpagesize gettimeofday inet_ntoa memset mkdir munmap select setlocale socket strcasecmp strchr strdup strerror strncasecmp strstr])

AC_CONFIG_FILES([Makefile
                 doc/Makefile
                 src/Makefile])
AC_OUTPUT
